package com.hadron.ui.form.comboBox 
{
	import com.greensock.TweenMax;
	import components.events.ButtonEvent;
	import components.templates.AbstractButton;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Hadron
	 */
	public class PhotoCenterComboBoxItem extends AbstractButton
	{
		private var _mc:MovieClip = new combo_box_item_mc();
		
		public function PhotoCenterComboBoxItem() 
		{
			super();
			init();
		}	
		
		private function init():void
		{
			addChild(mc);
			mc.mouseChildren = false;
			alpha = 0;
			mc.bg.alpha = 0;
			mc.tf.x = 4;
		}
		
		private function handleRollOver(e:MouseEvent):void 
		{
			performOver();
		}
		
		private function handleRollOut(e:MouseEvent):void 
		{
			performOut();
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			mouseChildren = false;
			performOut();
			dispatchEvent(new ButtonEvent(ButtonEvent.BUTTON_CLICKED));
		}
		
		private function performOver():void
		{
			TweenMax.to(mc.bg, .4, { alpha:.3} );
		}
		
		private function performOut():void
		{
			TweenMax.to(mc.bg, .4, { alpha:0} );
		}
		
		override public function transitionIn():void
		{
			super.transitionIn();
			TweenMax.to(this, .2, { alpha:1, onComplete:enable} );
		}
		
		override public function transitionOut():void
		{
			super.transitionOut();
			TweenMax.to(this, .2, { alpha:0} );
		}
		
		override public function set label(value:String):void
		{
			super.label = value;
			mc.tf.text = label;
		}
		
		public function get mc():MovieClip
		{
			return _mc;
		}
		
		override public function enable():void
		{
			super.enable();
			addEventListener(MouseEvent.CLICK, handleClick, false, 0, true);
			addEventListener(MouseEvent.ROLL_OVER, handleRollOver, false, 0, true);
			addEventListener(MouseEvent.ROLL_OUT, handleRollOut, false, 0, true);
		}
		
		override public function disable():void
		{
			super.disable();
			removeEventListener(MouseEvent.CLICK, handleClick);
			removeEventListener(MouseEvent.ROLL_OVER, handleRollOver);
			removeEventListener(MouseEvent.ROLL_OUT, handleRollOut);
		}
	}
}